﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AustalSystem.NetWork
{
    /// <summary>
    /// winUpdateHelp.xaml 的交互逻辑
    /// </summary>
    public partial class winUpdateHelp : Window
    {
        public winUpdateHelp()
        {
            InitializeComponent();
            backGroundWork.DoWork += new System.ComponentModel.DoWorkEventHandler(backGroundWork_DoWork);
            backGroundWork.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(backGroundWork_RunWorkerCompleted);
         
        }

        void backGroundWork_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {           
        
            this.labTitle.Text = Str;
            //this .Width=Str.Length+40;  
            
            if (this.ShowDialog().Value)
            {
                HANetwork.Network.DefaultNetWork.AuthenticationNetInfo.RunDownFilePage(HANetwork.Network.DefaultNetWork.UrlArg.DownLoadUrl[0]);
            }
        }
        public  string Str = "";
        void backGroundWork_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
              bool isNetWork = false;
            string mNetVersion =HANetwork.Network.DefaultNetWork .AuthenticationNetInfo.GetNetVersionNumber(HANetwork.Network.DefaultNetWork.UrlArg.VersionUrl, ref isNetWork);
            if (isNetWork)
            {
                string path = AppDomain.CurrentDomain.BaseDirectory + "HA.ModFlow.Presentation.exe";
                System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(path);
                System.Reflection.AssemblyName assemblyName = assembly.GetName();

                string oldVersionStr = assemblyName.Version.ToString(); // HANetwork.Network.DefaultNetWork.AuthenticationNetInfo.GetComputerVersion();
                int oldVersion = HANetwork.Network.DefaultNetWork.AuthenticationNetInfo.ConvertVersion(oldVersionStr);
                int newVersion = HANetwork.Network.DefaultNetWork.AuthenticationNetInfo.ConvertVersion(mNetVersion);

                if (newVersion > oldVersion)
                {
                    string str = "本程序当前版本为:" + oldVersionStr + "\r\n";
                    str += "本程序已更新到 " + mNetVersion + " 版本,请到 http://www.eia65.com 下载新版本程序,是否进行下载更新!";
                    Str = str;  
                }
            }
        }
        public  System.ComponentModel.BackgroundWorker backGroundWork = new System.ComponentModel.BackgroundWorker();

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {           
                HANetwork.Network.DefaultNetWork.AuthenticationNetInfo.RunDownFilePage(HANetwork.Network.DefaultNetWork.UrlArg.DownLoadUrl[0]);
                       this.DialogResult = true;
            this.Close();
        }

        private void btnCancal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //Run();
        }
        public void Run()
        {
            this.backGroundWork.RunWorkerAsync();
        }
    }
}
